import axios from "axios";
import config from "./config";
//判断环境的函数
const NowUrl = (type) => {
  let url;
  switch (type) {
    case "production":
      url = `${config.baseUrl.production}`;
      break;
    case "test":
      url = `${config.baseUrl.test}`;
      break;
    default:
      url = `${config.baseUrl.development}`;
  }
  return url;
};
//创建axios的实例
const request = axios.create({
  baseURL: NowUrl(process.env.NODE_ENV),
  timeout: 100000,
});
//允许携带凭证
// request.defaults.withCredentials = true;
//设置post请求头格式为x-www-form-urlencoded
request.defaults.headers["Content-Type"] = "application/x-www-form-urlencoded";
//请求拦截器
request.interceptors.request.use((config) => {
  return config;
});
//响应拦截器
request.interceptors.response.use((response) => {
  return response.data;
});
console.log(request.baseURL);
export default request;
